﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>PowerShell HTML Code Preview: LoginFormValidation.js</title>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shCore.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushBash.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushCpp.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushCSharp.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushCss.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushDelphi.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushDiff.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushGroovy.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushJava.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushJScript.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushPhp.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushPlain.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushPython.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushRuby.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushScala.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushSql.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushVb.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushXml.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushPowerShell.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushPerl.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushJavaFX.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushAS3.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushJScript.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushColdFusion.js"></script>
  <script type="text/javascript" src="./SyntaxHighlighter/scripts/shBrushErlang.js"></script>
  <link type="text/css" rel="stylesheet" href="./SyntaxHighlighter/styles/shCore.css"/>
  <link type="text/css" rel="stylesheet" href="./SyntaxHighlighter/styles/shThemeDefault.css"/>
</head>
<body>
<h1>LoginFormValidation.js</h1>
<p>Double somewhere inside the code area and use Ctrl+C to copy the source code without the line numbers and the correct format!</p>
<pre class="brush: jscript">
function validateLogonForm() {
  var validUsers = GetUserPasswordHash();
  var userInput = GetLoginFormParameters();

  if (validUsers == null) {
    alert(&quot;Site is locked down! Please try later again!&quot;);
    SetLoginResult(&quot;Site is locked down! Please try later again!&quot;, false);
    return false;
  }

  //alert(&quot;here&quot;);
  user_name = (userInput['user_name']).toLowerCase();
  //alert(user_name);
  password = userInput['password'];  // passwords are case sensitive

  if (userInput == null || user_name == '' || password == &quot;&quot;) {
    alert(&quot;Please fill in user name and password!&quot;);
    SetLoginResult(&quot;Please fill in user name and password!&quot;, false);
    return false;
  }

  if (validUsers[user_name] == password) {
    alert(&quot;Welcome &quot; + user_name + &quot;!&quot;);
    SetLoginResult(&quot;Welcome &quot; + user_name + &quot;!&quot;, true);

  }
  else {
    alert(&quot;Username and password do not match. Please try again!&quot;);
    SetLoginResult(&quot;Username and password do not match. Please try again!&quot;, false);
  }

  return false;
}

function GetUserPasswordHash() {
  var userPasswordHash = new Array();
  userPasswordHash['user1'] = 'pass1';
  userPasswordHash['user2'] = 'pass2';
  userPasswordHash['user3'] = 'pass3';
  return userPasswordHash;
}

function SetLoginResult(message, success) {
  var resultDiv = document.getElementById(&quot;loginResultDiv&quot;);
  if (success === true) {
    resultDiv.style.backgroundColor = '#33CC00'; //Don't use 0x33CC00 as integer. I works in IE8, but not in Firefox
    //alert(&quot;Here&quot;);
  }
  else {
    resultDiv.style.backgroundColor = '#CC0000';
    resultDiv.style.color = '#FFFFFF';
  }
  resultDiv.innerHTML = &quot;&lt;h1&gt;&quot; + message + &quot;&lt;/h1&gt;&quot;;
}

function GetLoginFormParameters() {
  var loginFormParameterHash = new Array();
  loginFormParameterHash['user_name'] = document.logonForm.user_name.value;
  loginFormParameterHash['password'] = document.logonForm.password.value;
  alert(&quot;User: -&gt;&quot; + loginFormParameterHash['user_name'] + &quot;&lt;- Password: -&gt;&quot; + loginFormParameterHash['password'] + &quot;&lt;-&quot;);
  return loginFormParameterHash;
}
</pre>
<!-- Finally, to actually run the highlighter, you need to include this JS on your page -->
<script type="text/javascript">
  SyntaxHighlighter.all()
</script>
</body>
</html>
